package com.ttbj.product.carriageRule.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.ttbj.api.carriageRule.CarriageRuleService;
import com.ttbj.api.dto.carriageRule.CarriageRuleDto;
import com.ttbj.api.exception.BusinessException;
import com.ttbj.carriageRule.bean.po.CarriageRule;
import com.ttbj.carriageRule.dao.CarriageRuleMapper;
import com.ttbj.constant.PlatFormErrorCode;
import com.ttbj.constant.annotation.SystemServiceLog;
import com.ttbj.core.util.DtoTransitionUtils;

@Service("carriageRuleService")
public class CarriageRuleServiceImpl implements CarriageRuleService{
	
	@Autowired
	private CarriageRuleMapper carriageRuleMapper;

	
	@Override
	public CarriageRuleDto findCarriageInfo() throws BusinessException {
		CarriageRule carriageRule = this.carriageRuleMapper.queryCarriageInfo();
		CarriageRuleDto carriageRuleDto = (CarriageRuleDto) DtoTransitionUtils.trans(CarriageRuleDto.class, carriageRule);
		return carriageRuleDto;
	}

	@Override
	@Transactional
	@SystemServiceLog(description="更改短运计价信息配置")
	public void editCarriageInfo(CarriageRuleDto carriageRuleDto) throws BusinessException {
		if (null == carriageRuleDto) {
			throw new BusinessException("参数有误", PlatFormErrorCode.OBJECT_DOES_NOT_EXIST.code());
		}
		CarriageRule carriageRule = (CarriageRule) DtoTransitionUtils.trans(CarriageRule.class, carriageRuleDto);
		int result = this.carriageRuleMapper.updateCarriageInfo(carriageRule);
		if (result == 0) {
			throw new BusinessException("更新失败", PlatFormErrorCode.DATA_SECURITY.code());
		}
	}

}
